package org.swirrel.example;

import org.swirrel.component.SwFrame;
import javax.swing.JButton;
import org.swirrel.annotation.ActionPerformed;
import org.swirrel.annotation.ActionWrapper;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import java.awt.FlowLayout;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;

/**
 * <p>Title: Swirrel</p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2009</p>
 *
 * <p>Company: </p>
 *
 * @author Daniel Gronau
 * @version 0.1
 */
public class ActionWrapperExampleSwFrame extends SwFrame {

  @ActionPerformed("call")
  private final JButton button = new JButton();
  @ActionPerformed("call")
  private final JMenuItem menuItem = new JMenuItem();

  public ActionWrapperExampleSwFrame() {
    super("Swirrel ActionWrapper example");
    setSize(500,500);
    JPanel panel = new JPanel(new FlowLayout(FlowLayout.CENTER));
    panel.add(button);
    getContentPane().add(panel);
    JMenuBar menuBar = new JMenuBar();
    menuBar.add(new JMenu("Menu")).add(menuItem);
    setJMenuBar(menuBar);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    setVisible(true);
  }

  @ActionWrapper(name="An Interesting Action",
                 shortDescription="short description",
                 largeIcon="calculate.png",   //this works in Java 1.6+ only
                 smallIcon="calculate_small.png",
                 mnemonicKey=java.awt.event.KeyEvent.VK_A)
  private void call() {
    JOptionPane.showMessageDialog(this, "I react!");
  }

  public static void main(String[] args) {
    new ActionWrapperExampleSwFrame();
  }

}
